﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Autodesk.Revit.DB;

namespace YJKFamilyLibManager.ForProject
{
	public partial class DlgFamilyProToPro : System.Windows.Forms.Form
	{
		public DlgFamilyProToPro(Dictionary<string, List<Family>> mapCatToFam)
		{
			this.mapCatToFamily = mapCatToFam;
			this.InitializeComponent();
			foreach (KeyValuePair<string, List<Family>> keyValuePair in this.mapCatToFamily)
			{
				string key = keyValuePair.Key;
				TreeNode treeNode = new TreeNode();
				treeNode.Text = key;
				treeNode.Tag = key;
				treeNode.Checked = true;
				this.tvFamily.Nodes.Add(treeNode);
				foreach (Family family in keyValuePair.Value)
				{
					TreeNode treeNode2 = new TreeNode();
					treeNode2.Text = string.Format("{0}", family.Name);
					treeNode2.Tag = family;
					treeNode2.Checked = true;
					treeNode.Nodes.Add(treeNode2);
				}
			}
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
		}

		private void DlgFamilyProToPro_Load(object sender, EventArgs e)
		{
		}

		private void btnAll_Click(object sender, EventArgs e)
		{
			this.selectAll(this.tvFamily.Nodes);
		}

		private void selectAll(TreeNodeCollection tnc)
		{
			foreach (object obj in tnc)
			{
				TreeNode treeNode = (TreeNode)obj;
				treeNode.Checked = true;
				this.selectAll(treeNode.Nodes);
			}
		}

		private void btnRev_Click(object sender, EventArgs e)
		{
			this.selectRev(this.tvFamily.Nodes);
		}

		private void selectRev(TreeNodeCollection tnc)
		{
			foreach (object obj in tnc)
			{
				TreeNode treeNode = (TreeNode)obj;
				treeNode.Checked = !treeNode.Checked;
				this.selectRev(treeNode.Nodes);
			}
		}

		private Dictionary<string, List<Family>> mapCatToFamily = new Dictionary<string, List<Family>>();
	}
}
